﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var currRowId = 0;
    var isJump = false;
    $(function () {
        initControl();
        gridList();
    });
    function initControl() {
        initBindSelect("#form1");
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/MainData/LogisticsInfo/GetLogisticsListJson",
            height: $(window).height() - 118,
            colModel: [
                { label: '单位编码', name: 'UnitNO', width: 80, align: 'left', sortable: false, frozen: true },
                { label: '单位全称', name: 'UnitFullName', width: 200, align: 'left', sortable: false, frozen: true },
                { label: '单位简称', name: 'UnitShortName', width: 140, align: 'left', sortable: false, frozen: true },
                { label: '负责人员', name: 'ResponUser', width: 80, align: 'left', sortable: false },
                { label: '联系人员', name: 'ContactUser', width: 80, align: 'left', sortable: false },
                { label: '联系电话', name: 'ContactPhone', width: 120, align: 'left', sortable: false },
                { label: '联系传真', name: 'ContactFax', width: 120, align: 'left', sortable: false },
                { label: '联系信箱', name: 'ContactEMail', width: 160, align: 'left', sortable: false },
                { label: '联系地址', name: 'ContactAdress', width: 200, align: 'left', sortable: false },
                { label: '创建人员', name: 'FCreateBy', width: 80, align: 'left', sortable: false },
                { label: '创建日期', name: 'FCreateDate', width: 80, align: 'center', sortable: false },
                { label: '创建时间', name: 'FCreateTime', width: 80, align: 'center', sortable: false },
                { label: '更改人员', name: 'FUpdateBy', width: 80, align: 'left', sortable: false },
                { label: '更改日期', name: 'FUpdateDate', width: 80, align: 'center', sortable: false },
                { label: '更改时间', name: 'FUpdateTime', width: 80, align: 'center', sortable: false },
                { label: '单位ID（隐藏）', name: 'UnitID', width: 80, align: 'center', sortable: false, hidden: true },
            ],
            pager: "#gridPager",
            sortname: 'UnitNO asc',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            rowNum: 1000000,
            gridComplete: function () {

            },
            loadComplete: function () {
                var rowDatas = $gridList.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList.jqGrid('setSelection', currRowId);
                    var $grid = $('#gview_gridList .ui-jqgrid-bdiv');
                    if (isJump) {
                        $grid.setScrollTop(length, currRowId);
                        isJump = false;
                    } else {
                        var top = $grid.scrollTop();
                        $grid.scrollTop(top + 1);
                    }
                }
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
                $('#btn_remove').removeClass("disabled");
                $('#btn_edit').removeClass("disabled");
            },
            onPaging: function (page_btn) {
                currRowId = 1;
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            reloadGrid();
        });
    }
    function reloadGrid(currNumber) {
        currNumber = currNumber || '';
        var currPage = 1;
        if (currNumber != "") {
            var data = {};
            var page = $('#gridList').getGridParam('page'); // current page
            var rows = $('#gridList').getGridParam('rowNum'); // rows
            var sidx = $('#gridList').getGridParam('sortname'); // sidx
            var sord = $('#gridList').getGridParam('sortorder'); // sord
            data["sidx"] = sidx;
            data["sord"] = sord;
            data["rows"] = rows;
            data["currNumber"] = currNumber;
            $.ajaxSetup({ async: false });
            $.getJSON("/MainData/LogisticsInfo/GetLogisticsInfoSortJson", data, function (result) {
                currPage = result.currPage;
                currRowId = result.currIndex;
            });
            $.ajaxSetup({ async: true });
            emptyDataById("#form1");
            isJump = true;
            $("#gridList").jqGrid('setGridParam', {
                page: currPage,
            }).trigger('reloadGrid');
        } else {
            isJump = false;
            $("#gridList").jqGrid('setGridParam', {
                postData: $("#form1").formSerialize(),
            }).trigger('reloadGrid');
        }

    }
    function btn_add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/MainData/LogisticsInfo/LogisticsInput"
        });
    }
    function btn_edit() {
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        var number = rowData.UnitID == undefined ? "" : rowData.UnitID;
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/MainData/LogisticsInfo/LogisticsInput?status=U&number=" + number
        });
    }
    function btn_remove() {
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        $.modalConfirm("注：您确定要【删除】该条数据吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/MainData/LogisticsInfo/SubmitLogisticsInfoForm?status=D",
                    param: { keyValue: rowData.UnitID },
                    success: function () {
                        reloadGrid();
                    }
                })
            }
        });
    }
    function btn_export() {
        var url = "/Common/ExcelExport?" + init_sql();
        location.href = url;
    }
    function init_sql() {
        var tablename = "ZSJ_C1_CY_Carrier";
        var condition = "UseUnit='@FriendStar.Code.Configs.GetValue("UseUnit")'";
        var cols = [];
        //获取列字段
        var colModel = $("#gridList").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#UnitNO').val() != '') {
            condition += " AND UnitNO LIKE '%" + $('#UnitNO').val() + "%'";
        }
        if ($('#UnitFullName').val() != '') {
            condition += " AND UnitFullName LIKE '%" + $('#UnitFullName').val() + "%'";
        }
        if ($('#UnitShortName').val() != '') {
            condition += " AND UnitShortName LIKE '%" + $('#UnitShortName').val() + "%'";
        }
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY UnitNO ASC";
        return "sql=" + sql;
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <form id="form1">
        <div style="padding: 12px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc; " class="line-table input-width-140">
            <div class="btn-group" style="margin-top:-9px;">
                单位编码<br /><input id="UnitNO" name="UnitNO" type="text" class="form-control " /> &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                单位全称<br /><input id="UnitFullName" name="UnitFullName" type="text" class="form-control " /> &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                单位简称<br /><input id="UnitShortName" name="UnitShortName" type="text" class="form-control " /> &nbsp;
            </div>
            <div class="btn-group" style="">
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div class="btn-group" style="float:right;">
                <a id="" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a id="btn_add" class="btn btn-primary center-block" onclick="btn_add()"><span class="glyphicon glyphicon-plus"></span> 新增</a>
                <a id="btn_remove" class="btn btn-primary center-block disabled" onclick="btn_remove()"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                <a id="btn_edit" class="btn btn-primary center-block disabled" onclick="btn_edit()"><span class="glyphicon glyphicon-edit"></span> 修改</a>
                <a id="btn_export" class="btn btn-primary center-block" onclick="btn_export()"><span class="glyphicon glyphicon-download"></span> 导出</a>
            </div>
        </div>
    </form>
    <div style="">
        <table id="gridList"></table>
    </div>
</div>

